import sys

sys.path.extend([".", ".."])
from c_ast_decl import ASTBuilder

builder = ASTBuilder()

# 构建条件表达式
cond = builder.expr(">", builder.var("x"), builder.const(5))

# ast = (
#     builder.if_else(cond=cond)
#     .then()  # 进入then块
#     .body(builder.func_call("log", ["x > 5"]))
#     .else_()  # 进入else块
#     .body(
#         builder.if_else(cond=builder.expr("<=", builder.var("y"), builder.const(6)))
#         # .then()
#         # .body(builder.func_call("log", ["x <= 5"]))
#         .end_if()
#     )
#     .end_if()
#     .build()
# )

# 验证生成的AST结构
from pycparser import c_generator

print(c_generator.CGenerator().visit(ast))
